package cn.cjlmonster.demo02.data;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Random;

import cn.cjlmonster.demo02.entity.Snapshot;

/**
 * This project is Demo02
 * Created by cjl on 2021/11/21 2:20 下午.
 */

public class SnapshotData {

    public enum Unit {
        day(15), week(15), month(8);

        public int range;

        Unit(int range) {
            this.range = range;
        }
    }

    public static List<Snapshot> createSnapshots(Unit unit) {
        switch (unit) {
            case day:
                return createDayData(unit.range);
            case week:
                return createWeekData(unit.range);
            case month:
                return createMonthData(unit.range);
            default:
                return new ArrayList<>();
        }
    }

    private static List<Snapshot> createDayData(int dayCount) {
        List<Snapshot> mData = new ArrayList<>();
        Random random = new Random();
        Calendar c = Calendar.getInstance();
        for (int i = 0; i < dayCount; i++) {
            c.add(Calendar.DAY_OF_MONTH, -1);
            int y = c.get(Calendar.YEAR);
            int m = c.get(Calendar.MONTH) + 1;
            int d = c.get(Calendar.DAY_OF_MONTH);
            int value = random.nextInt(100);
            String dateString = String.format(Locale.CHINA, "%04d-%02d-%02d", y, m, d);
            mData.add(new Snapshot(dateString, value));
        }
        return mData;
    }

    private static List<Snapshot> createWeekData(int weekCount) {
        List<Snapshot> mData = new ArrayList<>();
        Random random = new Random();
        Calendar c = Calendar.getInstance();
        for (int i = 0; i < weekCount; i++) {
            c.add(Calendar.WEEK_OF_MONTH, -1);
            int y = c.get(Calendar.YEAR);
            int m = c.get(Calendar.MONTH) + 1;
            int w = c.get(Calendar.WEEK_OF_MONTH);
            int value = random.nextInt(100);
            String dateString = String.format(Locale.CHINA, "%04d-%02d-%02d", y, m, w);
            mData.add(new Snapshot(dateString, value));
        }
        return mData;
    }

    private static List<Snapshot> createMonthData(int monthCount) {
        List<Snapshot> mData = new ArrayList<>();
        Random random = new Random();
        Calendar c = Calendar.getInstance();
        for (int i = 0; i < monthCount; i++) {
            c.add(Calendar.MONTH, -1);
            int y = c.get(Calendar.YEAR);
            int m = c.get(Calendar.MONTH) + 1;
            int value = random.nextInt(100);
            String dateString = String.format(Locale.CHINA, "%04d-%02d", y, m);
            mData.add(new Snapshot(dateString, value));
        }
        return mData;
    }
}
